package globalVisionEntertainment.nba;

import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Database
{

	public static Connection getConnection() throws IOException, SQLException
	{
		File directory = new File(".");
		File configFile;
		if (System.getProperty("debug", "false").equals("true"))
			configFile = new File(directory, "../connection.conf");
		else
			configFile = new File(directory, "connection.conf");

		try
		{
			String url;
			String user;
			String password;
			InputStreamReader reader = new InputStreamReader(new FileInputStream(configFile));
			BufferedReader br = new BufferedReader(reader);
			url = br.readLine();
			user = br.readLine();
			password = br.readLine();
			br.close();

			return DriverManager.getConnection(url, user, password);
		}
		catch (IOException e)
		{
			throw new IOException("connection.conf is not at " + directory.getCanonicalPath()
					+ ",\n or the config file doesn't have three rows, namely url, user name, and password", e);

		}
	}
}
